package com.ctsi.controller;

import com.ctsi.common.ResultVO;
import com.ctsi.entity.SysMenuOrg;
import com.ctsi.entity.req.AddSysUserMenuOrgReq;
import com.ctsi.service.SysMenuOrgService;
import com.ctsi.ssdc.security.SecurityUtils;
import com.ctsi.ssdc.security.jwt.TokenProvider;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

<<<<<<< HEAD
=======
import javax.validation.Valid;
import java.util.Date;

>>>>>>> 68aa1d90d2566d16418fa4b72fc5cda36fdfbb57

@Slf4j
@RestController
@RequestMapping("/api/SysMenuOrg")
@Api(tags = "系统管理机构单位管理接口")
public class SysMenuOrgController {

    @Autowired
    private SysMenuOrgService sysMenuOrgService;

    @Autowired
    TokenProvider tokenProvider;


    @ApiOperation(value = "机构查询接口", notes = "根据机构ID查询机构信息")
    @GetMapping(value = "/selectSysMenuOrgByOrgId")
    public ResultVO<SysMenuOrg> selectSysMenuByOrgId() {
        int uid = SecurityUtils.getCurrentUserId();
        log.info("SysMenuOrgController.selectSysMenuByOrgId uid={}", uid);
        return sysMenuOrgService.selectSysMenuByOrgId((long) uid);
    }


    @PreAuthorize("@permissionService.hasPermi('cscp.syy.add')")
    @ApiOperation(value = "添加组织机构接口", notes = "添加机构信息")
    @PostMapping(value = "/insertSysMenuOrg")
    public ResultVO insertSysMenuOrg(@Valid @RequestBody AddSysUserMenuOrgReq req) {
        log.info("SysMenuOrgController.insertSysMenuOrg req={}", req);
        req.setCreateStaffId((long)SecurityUtils.getCurrentUserId());
        req.setCreateStaff(SecurityUtils.getCurrentUserName());
        req.setCreateTime(new Date());
        return sysMenuOrgService.insertSysMenuOrg(req);
    }

    @PreAuthorize("@permissionService.hasPermi('cscp.syy.updata')")
    @ApiOperation(value = "更新组织机构接口", notes = "更新机构信息")
    @PostMapping(value = "/updateSysMenuOrgByOrgId")
    public ResultVO updateSysMenuOrgByOrgId(@RequestBody SysMenuOrg sysMenuOrg) {
        log.info("SysMenuOrgController.updateSysMenuOrgByOrgId sysMenuOrg={}", sysMenuOrg);
        return sysMenuOrgService.updateSysMenuOrgByOrgId(sysMenuOrg);
    }

    @PreAuthorize("@permissionService.hasPermi('cscp.syy.delet')")
    @ApiOperation(value = "删除组织机构接口", notes = "删除机构信息")
    @DeleteMapping(value = "/deleteSysMenuByOrgId/{id}")
    public ResultVO deleteSysMenuByOrgId(@PathVariable(value = "id", required = false) Long id) {
        log.info("SysMenuOrgController.deleteSysMenuByOrgId id={}", id);
        return sysMenuOrgService.deleteSysMenuByOrgId(id);
    }

    @ApiOperation(value = "获取组织机构列表")
    @GetMapping("/list")
    public ResultVO list(SysMenuOrg sysMenuOrg){
        return sysMenuOrgService.getlist(sysMenuOrg);
    }

    @ApiOperation(value = "查询组织列表（排除节点）")
    @GetMapping("/exclude/{id}")
    public ResultVO excludeChild(@PathVariable(value = "deptId", required = false) Long id){
        return sysMenuOrgService.excludeChild(id);
    }

    @ApiOperation(value = "查询指定机构下的所有用户")
    @GetMapping("/selectUserList/{id}")
    public ResultVO selectUserList(@PathVariable(value = "id", required = false) Long id){
        return sysMenuOrgService.selectUserlist(id);
    }

    @ApiOperation(value = "查询指定机构下的所有用户")
    @GetMapping("/selectOrgList/{id}")
    public ResultVO selectOrgList(@PathVariable(value = "id", required = false) Long id){
        return sysMenuOrgService.selectOrgList(id);
    }
}
